const tagList = {
  state: {
    tagsList: [],
  },
  getters: {
    tagsList: state => {
      return state.tagsList
    }
  },
  mutations: {
    delTagsItem: (state, data) => {
      state.tagsList.splice(data.index, 1)
    },
    appendTagsItem(state, data){
      state.tagsList.push(data)
    },
    clearTagsList(state){
      state.tagsList = []
    },
    closeTagsOther(state, data) {
      state.tagsList = data;
    },
    closeCurrentTag(state, data) {
      for (let i = 0, len = state.tagsList.length; i < len; i++) {
        const item = state.tagsList[i];
        if (item.path === data.$route.path) {
          if (i < len - 1) {  // 删除除最后一个标签默认进入后一个标签的页面
            data.$router.push(state.tagsList[i + 1].path);
          } else if (i > 0) {   // 删除最后一个标签向前进一个标签
            data.$router.push(state.tagsList[i - 1].path);
          } else {    // 没有标签则进入后台首页
            data.$router.push("/back-stage");
          }
          state.tagsList.splice(i, 1);
          break;
        }
      }
    },
  },
}

export default tagList
